package office.action.sale;

import java.util.Date;
import java.util.List;
import java.util.Map;

import office.action.sale.form.SaleChanceConditionForm;
import office.action.sale.form.SaleChanceForm;
import office.action.sale.wrapper.SaleChanceWrapper;
import office.service.sale.ISaleChanceService;
import platform.common.action.BaseAction;
import platform.common.bo.Page;
import platform.util.Util;

/**
 * 
 * 销售机会
 * 
 * @author ZhangYQ
 * 
 */
public class SaleChanceAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private ISaleChanceService saleChanceService;
	private Page page; // 分页信息
	private List<SaleChanceWrapper> saleChanceWrapperList;
	private SaleChanceForm saleChanceForm;
	private SaleChanceConditionForm condition;
	private String id;
	@SuppressWarnings("unchecked")
	private Map map;

	/**
	 * 获取所有的销售机会
	 * 
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String findAllSaleChance() throws Exception {
		page = saleChanceService.getPageInfo();
		saleChanceWrapperList = saleChanceService.findAllPriceData(page);
		map = Util.parsePropertiesReturnMap("project", "chanceSource.size");
		return "findAllSaleChance";
	}

	/**
	 * 初始化编辑销售机会页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEditSaleChance() throws Exception {
		if(null!=id&&!"".equals(id)){
			saleChanceForm = saleChanceService.getById(id);
		}
		map = Util.parsePropertiesReturnMap("project", "chanceSource.size");
		return "gotoEditSaleChance";
	}

	/**
	 * 编辑销售机会
	 * 
	 * @return
	 * @throws Exception
	 */
	public String editSaleChance() throws Exception {
		try {
			if (null == saleChanceForm.getId()
					|| ("").equals(saleChanceForm.getId())) {
				saleChanceForm.setCreateDate(new Date());
				this.getAjaxMessagesJson().setMessage(true, "", "新建成功");
			} else {
				this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
			}
			saleChanceService.editSaleChance(saleChanceForm);

		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}

	/**
	 * 
	 * <br/>
	 * 方法描述:分页条件查询价格数据
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listSaleChanceByPage() throws Exception {
		try {
			saleChanceWrapperList = saleChanceService
					.findAllSaleChanceByCondition(condition, page);
			map = Util.parsePropertiesReturnMap("project", "chanceSource.size");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "listSaleChanceByPage";
	}
	/**
	 * 根据条件查询销售机会
	 * @return
	 * @throws Exception
	 */
	
	public String searchSaleChanceBySearchKey() throws Exception {
		try {
			page = saleChanceService.getPageInfoByCondition(condition);
			saleChanceWrapperList = saleChanceService.findAllSaleChanceByCondition(condition,page);
			map = Util.parsePropertiesReturnMap("project", "chanceSource.size");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return "searchSaleChanceBySearchKey";
	}

	/**
	 * 初始化销售机会列表操作菜单
	 * 
	 * @return
	 * @throws Exception
	 */

	public String gotoSaleChanceManageMenu() throws Exception {
		return "gotoSaleChanceManageMenu";
	}

	/**
	 * 跳转到价格数据删除确认页面
	 */
	public String gotoDeleteSaleChance(){
		return "gotoDeleteSaleChance";
	}
	
	/**
	 * 删除价格数据
	 * @return
	 * @throws Exception
	 */
	public String delSaleChanceManage() throws Exception {
		try {
			saleChanceService.delSaleChanceManageById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "操作成功");
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			throw e;
		}
		return RESULT_AJAXJSON;
	}
	
	public SaleChanceForm getSaleChanceForm() {
		return saleChanceForm;
	}

	public void setSaleChanceForm(SaleChanceForm saleChanceForm) {
		this.saleChanceForm = saleChanceForm;
	}

	public platform.common.bo.Page getPage() {
		return page;
	}

	public void setPage(platform.common.bo.Page page) {
		this.page = page;
	}

	public List<SaleChanceWrapper> getSaleChanceWrapperList() {
		return saleChanceWrapperList;
	}

	public void setSaleChanceWrapperList(
			List<SaleChanceWrapper> saleChanceWrapperList) {
		this.saleChanceWrapperList = saleChanceWrapperList;
	}

	public ISaleChanceService getSaleChanceService() {
		return saleChanceService;
	}

	public void setSaleChanceService(ISaleChanceService saleChanceService) {
		this.saleChanceService = saleChanceService;
	}

	public SaleChanceConditionForm getCondition() {
		return condition;
	}

	public void setCondition(SaleChanceConditionForm condition) {
		this.condition = condition;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	@SuppressWarnings("unchecked")
	public Map getMap() {
		return map;
	}
	@SuppressWarnings("unchecked")
	public void setMap(Map map) {
		this.map = map;
	}

}
